#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Collections.ObjectModel;

namespace UTable.Input.MultiTouch
{
	public class FingerEventArgs
	{
		public FingerEventArgs()
		{
            this.TimeTrace.StarTime = InputEventArgs.GetTimestamp();
		}

		public FingerEventArgs(FingerEventType type, int id, Point position)
		{
			this.EventType = type;
			this.FingerID = id;
			this.Position = position;
			this.GlobalPosition = position;
            this.TimeTrace.StarTime = InputEventArgs.GetTimestamp();
		}

		public FingerEventArgs(FingerEventType type, int id, Point position, int userID)
		{
			this.EventType = type;
			this.FingerID = id;
			this.Position = position;
			this.GlobalPosition = position;
			this.UserID = userID;
            this.TimeTrace.StarTime = InputEventArgs.GetTimestamp();
		}

		/// <summary>
		/// The type of this finger event type
		/// See the definition of FingerEventType enum
		/// </summary>
		public FingerEventType EventType;
		
		/// <summary>
		/// The ID of the finger that causes this event
		/// FingerID is the unique mark to distinguish different fingers
		/// </summary>
		public int FingerID;

		/// <summary>
		/// The position on which this event occurs relative to the coordinate system of the UElement this event is sent to
		/// </summary>
		public Point Position;

		/// <summary>
		/// The position relative to the screen
		/// </summary>
		public Point GlobalPosition;

        /// <summary>
        /// The orientation of the finger values from 0 to 360
        /// right is zero
        /// </summary>
        public double Orientation;

		/// <summary>
		/// The ID of the user who triggers the finger event
		/// This ID can uniquely mark a user
		/// </summary>
		public int UserID;

        public const int PureFingerID = 0;

		/// <summary>
		///     Gets or sets a value that indicates the present state of the event handling
		///     for a routed event as it travels the route.
		/// </summary>
		public bool Handled = false;

        public int SourceID = 0;
        
        /// <summary>
        /// Gets the time when this event occurred
        /// </summary>
        public long Timestamp
        {
            get;
            set;
        }

        /// <summary>
        /// The name of the device that creates this event
        /// </summary>
        public String DeviceName = String.Empty;

        /// <summary>
        /// Get the time trace for this input args
        /// This field is only used for debug
        /// </summary>
        public TimeTrace TimeTrace = new TimeTrace();

        /// <summary>
        /// Mark whether this finger event is captured by an visual node
        /// Set by Input Event Args, and used to dispatch events
        /// </summary>
        internal bool Captured = false;
	}

    public class TimeTrace
    {
        public int Step = 0;

        public void SetStep(int s)
        {
            if (s - 1 != Step)
            {
                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!Wrong Step!!!!!!!!!!!!!!!: " + Step + "-> " + s);
            }
            Step = s;
        }

        public long StarTime;

        public long GlobalObjectManagerTime;

        public long BeforeSendUObjectTime;

        public long AfterSendUObjectTime;

        public long UObjectTime;
    }

	public enum FingerEventType
	{
		FINGER_DOWN_EVENT = 0,
		FINGER_MOVE_EVENT,
		FINGER_UP_EVENT,
        FINGER_IN_EVENT,
        FINGER_OUT_EVENT
	}
}
